/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gestionservicio.model.dao.impl;

import gestionservicio.model.dao.interfaces.PersonaDao;
import gestionservicio.model.businessobject.Persona;

// Hibernate Spring DAO Para que me soporte
import java.sql.SQLException;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 *
 * @author principal
 */
public class PersonaDaoImpl extends HibernateDaoSupport implements PersonaDao {

    public int savePersona(Persona persona) {
        this.getHibernateTemplate().save("PersonaTable", persona);
        return 1;
    }

    public Persona getPersona(final Integer cedulaPersona) {
        return (Persona) this.getHibernateTemplate().execute(new HibernateCallback() {

            public Object doInHibernate(Session session)
                    throws HibernateException, SQLException {
                Persona persona =
                        (Persona) session.createCriteria("PersonaTable")
                        .add(Restrictions.eq("cedula", cedulaPersona))
                        .uniqueResult();

                return persona;
            }
        });
    }

    public boolean updatePersona(Persona persona) {
        this.getHibernateTemplate().update(persona);
        return true;
    }

    public boolean deletePersona(Persona persona) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

}
